package com.app.xinfadi.util;

import android.util.Log;


import com.app.xinfadi.util.log.Logger;

import java.text.SimpleDateFormat;
import java.util.Date;

public class LogUtil {
	private static final boolean LOG_DEBUG = true;
	/**
	 * 缓存logger debug 开关
	 */
	private static final boolean LOGGER_DEBUG = true;

	public static void d(String TAG, String method, String msg) {
		if (LOG_DEBUG) {
			Log.d(TAG, "[" + method + "]" + msg);
		}
	}

	public static void d(String TAG, String msg) {
		if (LOG_DEBUG) {
//			Log.d(TAG, "[" + getFileLineMethod() + "]" + msg);
			if (LOGGER_DEBUG)
				Logger.d(TAG, "[" + getFileLineMethod() + "]" + msg);
		}
	}

	public static void d(String msg) {
		if (LOG_DEBUG) {
			Log.d(_FILE_(), "[" + getLineMethod() + "]" + msg);
		}
	}

	public static void e(String msg) {
		if (LOG_DEBUG) {
			// Log.e(_FILE_(), getLineMethod() + msg);
			Log.e(_FILE_(), "[" + getFileLineMethod() + "]" + msg);
		}
	}

	public static void e(String TAG, String msg) {
		if (LOG_DEBUG) {
			// Log.e(TAG, "[" + getFileLineMethod() + "]" + msg);
			if (LOGGER_DEBUG)
				Logger.e(TAG, "[" + getFileLineMethod() + "]" + msg);
		}
	}

	public static void i(String msg) {
		if (LOG_DEBUG) {
			Log.i(_FILE_(), "[" + getFileLineMethod() + "]" + msg);
		}
	}

	public static void i(String TAG, String msg) {
		if (LOG_DEBUG) {
			Log.i(TAG, "[" + getFileLineMethod() + "]" + msg);
		}
	}

	public static void v(String msg) {
		if (LOG_DEBUG) {
			Log.v(_FILE_(), "[" + getFileLineMethod() + "]" + msg);
		}
	}

	public static void v(String TAG, String msg) {
		if (LOG_DEBUG) {
			// Log.v(TAG, "[" + getFileLineMethod() + "]" + msg);
			if (LOGGER_DEBUG)
				Logger.v(TAG, "[" + getFileLineMethod() + "]" + msg);
		}
	}

	public static void w(String msg) {
		if (LOG_DEBUG) {
			Log.w(_FILE_(), "[" + getFileLineMethod() + "]" + msg);
		}
	}

	public static void w(String TAG, String msg) {
		if (LOG_DEBUG) {
			Log.w(TAG, "[" + getFileLineMethod() + "]" + msg);
		}
	}

	public static String getFileLineMethod() {
		StackTraceElement traceElement = ((new Exception()).getStackTrace())[2];
		StringBuffer toStringBuffer = new StringBuffer("[").append(traceElement.getFileName()).append(" | ")
				.append(traceElement.getLineNumber()).append(" | ").append(traceElement.getMethodName()).append("]");
		return toStringBuffer.toString();
	}

	public static String getLineMethod() {
		StackTraceElement traceElement = ((new Exception()).getStackTrace())[2];
		StringBuffer toStringBuffer = new StringBuffer("[").append(traceElement.getLineNumber()).append(" | ")
				.append(traceElement.getMethodName()).append("]");
		return toStringBuffer.toString();
	}

	public static String _FILE_() {
		StackTraceElement traceElement = ((new Exception()).getStackTrace())[2];
		return traceElement.getFileName();
	}

	public static String _FUNC_() {
		StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
		return traceElement.getMethodName();
	}

	public static int _LINE_() {
		StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
		return traceElement.getLineNumber();
	}

	public static String _TIME_() {
		Date now = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ImageBrowserAdapter.SSS");
		return sdf.format(now);
	}
}
